require "proto/skill/message/ReqImitationSkillMessage"
require "proto/skill/message/ReqLevUpAssistantSkillMessage"
require "proto/skill/message/ReqAssistantSkillMessage"
require "proto/skill/message/ReqSelectAssistantSkillMessage"
require "proto/skill/message/ReqResetAssistantSkillMessage"
require "proto/skill/message/ReqPetSkillSetInfoListMessage"
require "proto/skill/message/ReqAlterPetSkillSetMessage"
require "proto/skill/message/ReqSetFormationSkillAiMessage"
skillHandler = skillHandler or {};
G.serverData = G.serverData or {};

function skillHandler.receiveSendImitationSkill(msg)
    --log("skillHandler.receiveSendImitationSkill");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        local skillList = msg.skillList;
        if skillList ~= nil and #skillList > 0 then
            for i = 1, #skillList do
                if skillList[i] > 0 then
                    logicMgr.HeroManager.setImitationSkill(skillList[i]);
                end
            end
        end
    end
end

function skillHandler.receiveAssistantSkill(msg)
    logicMgr.SkillManager.setSupSkillInfo(msg);
    FireEvent(Config.EventType.AssistantSkill);
end

function skillHandler.receiveFormationAssistantSkillPush(msg)
    local skillList = msg.skillList;
    logicMgr.SkillManager.initFormationAssistantSkillList(0,nil);
    for i, v in pairs(skillList) do
        logicMgr.SkillManager.initFormationAssistantSkillList(v.type,v.skillId);
    end
end

function skillHandler.receiveResetAssistantSkill(msg)
end

function skillHandler.receiveLevUpAssistantSkill(msg)
    if msg.skillId  and  msg.state == 0 then
        SkillManager.setSupSkillSrverData(msg);
        FireEvent(Config.EventType.LevUpAssistantSkill);
    end
end

function skillHandler.receiveImitationSkill(msg)
    --log("skillHandler.receiveImitationSkill");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        logicMgr.HeroManager.setImitationSkill(msg.skillId);
        FireEvent(Config.EventType.Fresh_Skill);
    end
end

function skillHandler.sendImitationSkill(partnerId, skillId)
    local req = ReqImitationSkillMessage.New();
    req.partnerId = partnerId;
    req.skillId = skillId;
    sendReqMessage(req);
end

function skillHandler.SendLevUpAssistantSkill(skillId)
    local req = ReqLevUpAssistantSkillMessage.New();
    req.skillId = skillId;
    sendReqMessage(req);
end

function skillHandler.SendReqAssistantSkill()
    local req = ReqAssistantSkillMessage.New();
    sendReqMessage(req);
end

function skillHandler.SendReqSelectAssistantSkillMessage(skillId,formationType)
    local req = ReqSelectAssistantSkillMessage.New();
    req.skillId = skillId;
    req.formationType = formationType;
    logicMgr.SkillManager.selectSupSkill(skillId);
    sendReqMessage(req);

end

function skillHandler.SendReqResetSkill(skillId)
    local req = ReqResetAssistantSkillMessage.New();
    req.skillId = skillId;
    sendReqMessage(req);
end
--魂印技能
function skillHandler.SendReqPetSkillList()
    local req = ReqPetSkillSetInfoListMessage.New()
    sendReqMessage(req);
end

function skillHandler.SendReqChangePetSkill(skillId,formationType)
    local req = ReqAlterPetSkillSetMessage.New()
    req.petSkillId = skillId
    req.formationType = formationType
    sendReqMessage(req);
end

function skillHandler.receiveResPetSkillList(msg)
    for _,v in pairs(msg.petSkillSetList) do
        SkillManager.initFormationPetSkillList(v.type, v.skillId)
    end
end

function skillHandler.receiveResChangePetSkill(msg)
    SkillManager.initFormationPetSkillList(msg.formationType, msg.petSkillId)
    FireEvent(Config.EventType.ChangePetSkill)
end

function skillHandler.SendReqSetFormationSkillAi(formationType, data)
    local req = ReqSetFormationSkillAiMessage.New()
    req.type = formationType
    req.heroAiList = data;
    dump(req, "技能发送 ")
    sendReqMessage(req);
end

function skillHandler.receiveResFormationSkillAi(msg)
    if msg.state == 0 then
        logicMgr.HeroManager.setChooseHeroById(msg.formationSkillAiList);
    end
end